const { prisma } = require('../config/prisma');

async function checkListing() {
  try {
    const listing = await prisma.listings.findUnique({
      where: { id: BigInt(43) },
      select: {
        id: true,
        company_name: true,
        audit_status: true,
        status: true,
        created_at: true,
        auto_publish_at: true,
        audit_time: true,
        audit_admin_id: true,
        audit_comment: true
      }
    });

    if (listing) {
      const now = new Date();
      console.log('=== ID 43 挂牌信息详情 ===\n');
      console.log(`公司名称: ${listing.company_name}`);
      console.log(`审核状态: ${listing.audit_status}`);
      console.log(`上架状态: ${listing.status}`);
      console.log(`创建时间: ${listing.created_at.toLocaleString('zh-CN')}`);
      console.log(`自动发布时间: ${listing.auto_publish_at ? listing.auto_publish_at.toLocaleString('zh-CN') : 'null'}`);
      console.log(`审核时间: ${listing.audit_time ? listing.audit_time.toLocaleString('zh-CN') : 'null'}`);
      console.log(`审核管理员ID: ${listing.audit_admin_id || 'null'}`);
      console.log(`审核备注: ${listing.audit_comment || 'null'}`);
      console.log(`\n当前时间: ${now.toLocaleString('zh-CN')}`);

      if (listing.auto_publish_at) {
        const diff = listing.auto_publish_at - now;
        const minutes = Math.floor(Math.abs(diff) / 1000 / 60);
        const seconds = Math.floor((Math.abs(diff) / 1000) % 60);

        if (diff > 0) {
          console.log(`距离自动发布: 还有 ${minutes}分${seconds}秒`);
        } else {
          console.log(`距离自动发布: 已超时 ${minutes}分${seconds}秒`);
        }
      }
    } else {
      console.log('ID 43 的信息不存在');
    }
  } catch (error) {
    console.error('查询失败:', error);
  } finally {
    await prisma.$disconnect();
  }
}

checkListing();
